<?php

namespace App\Http\Controllers;

use App\Models\Wxuser;
use App\Models\WxuserWxcard;
use App\Repositories\IndexRepository;

class MumuController extends Controller
{
    protected $foo;


    public function index(IndexRepository $indexRepository)
    {
        //session([config('services.wechat.wauth_session_name')=>Wxuser::find(1)]);
        $wxuser = Wxuser::find(session(config('services.wechat.wauth_session_name'))->id);

        $card = $indexRepository->getWxCardByUid();

        $total_card = WxuserWxcard::where('id_wxusers',$wxuser->id)->count();

        return view('index',compact('wxuser','card','total_card'));
    }

    public function wcardForUser(IndexRepository $indexRepository)
    {
        $wx_card_to_user = $indexRepository->getWxCardByUid();

        return response()->json($wx_card_to_user);
    }
    /*
     * 获取星星规则
     */
    public function getStartRules()
    {
        return view('get_start_rules');
    }

    /*
     * 获取的卡券列表
     */
    public function WxcardList(IndexRepository $repository)
    {
        //session([config('services.wechat.wauth_session_name')=>Wxuser::find(30)]);
        $star_first = session(config('services.wechat.wauth_session_name'))->Stars()
            ->orderBy('created_at','asc')->first();

        $star_first_time = date('m月d日',strtotime($star_first->created_at));

        $star_sum = session(config('services.wechat.wauth_session_name'))->Stars()
            ->count('*');
        $cards = $repository->getUserCardHistory();

        return view('get_wxcard_list',compact('cards','star_first_time','star_sum'));
    }
}
